#region Disclaimer by Teo Lachev
/*============================================================================
  The CustomDataExtension sample uses code from the Microsoft File Share Data 
  Processing Extension Sample (http://msdn2.microsoft.com/en-us/library/ms160918.aspx). 
  The orginal code base has been modified whenever needed to re-purpose the 
  extension to support ADO.NET datasets. Most code changes are implemented in the 
  DsDataReader class.
===========================================================================*/
#endregion

using System;
using Microsoft.ReportingServices.DataProcessing;
using Microsoft.ReportingServices.Interfaces;


namespace Prologika.RS.Extensibility.CustomDataExtension
{
    /// <summary>
    /// Represents a connection
    /// </summary>
	public class DsConnectionWrapper : IDbConnection, IDbConnectionExtension, IExtension
	{
		private string                         m_connString;
		private System.Data.ConnectionState    m_state = System.Data.ConnectionState.Closed;
		private string                         m_locName = "Dataset Extension";	// as it appears in the dataset dropdown
		private string                         m_impersonate;
		private bool                           m_integratedSecurity;
		private string                         m_username;
		private string                         m_password;
      
		public DsConnectionWrapper()
		{
			// TODO: Implement a default constructor
		}
    
		// Have a constructor that takes a connection string.
		public DsConnectionWrapper(string connString)
		{

			m_connString = connString;
		}



	/****
	  * IMPLEMENT THE REQUIRED PROPERTIES.
	  ****/
	public string ConnectionString
{
	get
{
	// Always return exactly what the user set.
	// Security-sensitive information may be removed.
	return m_connString;
}
	set
{
	m_connString = value;
}
}

	public int ConnectionTimeout
{
	get
{
	// Returns the connection time-out value set in the connection
	// string. Zero indicates an indefinite time-out period.
	return 0;
}
}

	public System.Data.ConnectionState State
{
	get 
{
	return m_state;
}
}

	/****
	  * IMPLEMENT THE REQUIRED METHODS.
	  ****/

	public IDbTransaction BeginTransaction()
{
	throw new NotSupportedException();
}

	public void Open()
	{
		/*
			* Open the database connection and set the ConnectionState
			* property. If the underlying connection to the server is 
			* expensive to obtain, the implementation should provide
			* implicit pooling of that connection.
			* 
			* If the provider also supports automatic enlistment in 
			* distributed transactions, it should enlist during Open().
			*/
		// nothing to open, just set the state
		System.Diagnostics.Trace.WriteLine("DsConnection Open");
		m_state = System.Data.ConnectionState.Open;
		return;
	}

	public void Close()
{
	/*
		 * Close the database connection and set the ConnectionState
		 * property. If the underlying connection to the server is
		 * being pooled, Close() will release it back to the pool.
		 */
	m_state = System.Data.ConnectionState.Closed;
	return;
}

	public IDbCommand CreateCommand()
{
	// Return a new instance of a command object.
	return new DsCommand(this);
}

	/****
	  * REQUIRED METHODS / PROPERTIES FROM IExtension.
	  ****/
      
	public string LocalizedName
{
	get
{
	// Always return exactly what the user set.
	// Security-sensitive information may be removed.
	return m_locName;
}
	set
{
	m_locName = value;
}
}

	public void SetConfiguration(string configuration)
{
	// Used to retrieve configuration data from the config file
}

	/****
		 * REQUIRED METHODS / PROPERTIES FROM IDbConnectionExtension.
		 ****/
	/*
	  * For data sources that require credentials, these properties
	  * add support for storing secure credentials while designing
	  * reports with Report Designer. The Data Source dialog will
	  * include support for the Integrated checkbox as well as
	  * text boxes for username and password.
	  */
	public bool IntegratedSecurity
{
	get
{
	return m_integratedSecurity;
}
	set
{
	m_integratedSecurity = value;
}
}

	public string UserName
{
	get
{
	return m_username;
}
	set
{
	m_username = value;
}
}

	public string Password
{
	get
{
	return m_password;
}
	set
{
	m_password = value;
}
}

	public string Impersonate
{
	get
{
	return m_impersonate;
}
	set
{
	m_impersonate = value;
}
}
      
	public void Dispose() 
{
}
}
}

